package com.bakery.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bakery.entity.SalesLog;
import com.bakery.mapper.SalesLogMapper;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * 销售日志Service
 *
 * @author bakery
 */
@Service
public class SalesLogService extends ServiceImpl<SalesLogMapper, SalesLog> {
    
    /**
     * 分页查询销售日志
     */
    public Page<SalesLog> getSalesLogPage(Integer page, Integer size, String orderNo, 
                                          LocalDateTime startTime, LocalDateTime endTime, Long employeeId) {
        LambdaQueryWrapper<SalesLog> wrapper = new LambdaQueryWrapper<>();
        
        if (StrUtil.isNotBlank(orderNo)) {
            wrapper.like(SalesLog::getOrderNo, orderNo);
        }
        
        if (startTime != null) {
            wrapper.ge(SalesLog::getOperationTime, startTime);
        }
        
        if (endTime != null) {
            wrapper.le(SalesLog::getOperationTime, endTime);
        }
        
        if (employeeId != null) {
            wrapper.eq(SalesLog::getEmployeeId, employeeId);
        }
        
        wrapper.orderByDesc(SalesLog::getOperationTime);
        
        return page(new Page<>(page, size), wrapper);
    }
}

